const loki = require('lokijs')

// var db = new loki('example.db', { autoload: true });
var db = new loki('example.db', {
    autoload: true,
    autoloadCallback: databaseInitialize,
    autosave: true,
    autosaveInterval: 4000
});

// implement the autoloadback referenced in loki constructor
function databaseInitialize() {
    var users = db.getCollection("users");
    if (users === null) {
        users = db.addCollection("users");
    }
    // kick off any program logic or start listening to external events
    runProgramLogic();
}

// example method with any bootstrap logic to run after database initialized
function runProgramLogic() {
    var users = db.getCollection("users")
    var results = users.find({ age: { '$gte': 35 } });

    var odin = users.findOne({ name: 'Odin' });

    var aaa = users.by("name", "Odin")

    var results2 = users.where(function (obj) {
        return (obj.age >= 35);
    });

    console.log(results, odin, results2)
}

